﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ShopeeWebApi.Migrations
{
    public partial class init : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Area",
                columns: table => new
                {
                    AreaId = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    AreaName = table.Column<string>(type: "TEXT", nullable: false),
                    ShorterForm = table.Column<string>(type: "TEXT", nullable: false),
                    Platform = table.Column<int>(type: "INTEGER", nullable: false),
                    ShopId = table.Column<int>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Area", x => x.AreaId);
                });

            migrationBuilder.CreateTable(
                name: "Attribute",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    AttributeId = table.Column<long>(type: "INTEGER", nullable: false),
                    OriginalName = table.Column<string>(type: "TEXT", nullable: false),
                    DisplayName = table.Column<string>(type: "TEXT", nullable: false),
                    IsMandatory = table.Column<int>(type: "INTEGER", nullable: false),
                    InputType = table.Column<int>(type: "INTEGER", nullable: false),
                    FormatType = table.Column<int>(type: "INTEGER", nullable: false),
                    DateFormatType = table.Column<int>(type: "INTEGER", nullable: false),
                    Type = table.Column<int>(type: "INTEGER", nullable: false),
                    AttributeUnit = table.Column<string>(type: "TEXT", nullable: false),
                    AttributeValuesList = table.Column<string>(type: "TEXT", nullable: false),
                    FromRawID = table.Column<string>(type: "TEXT", nullable: true),
                    RSRID = table.Column<string>(type: "TEXT", nullable: true),
                    Platform = table.Column<int>(type: "INTEGER", nullable: false),
                    AddTime = table.Column<DateTime>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Attribute", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Category",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    CategoryId = table.Column<long>(type: "INTEGER", nullable: false),
                    CategoryParentId = table.Column<long>(type: "INTEGER", nullable: false),
                    OriginalNname = table.Column<string>(type: "TEXT", nullable: false),
                    DisplayName = table.Column<string>(type: "TEXT", nullable: false),
                    HasChildren = table.Column<bool>(type: "INTEGER", nullable: false),
                    AddTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    Platform = table.Column<int>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Category", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "UserInfo",
                columns: table => new
                {
                    ID = table.Column<int>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ShopId = table.Column<int>(type: "INTEGER", nullable: false),
                    AccessToken = table.Column<string>(type: "TEXT", nullable: false),
                    ExpireIn = table.Column<long>(type: "INTEGER", nullable: false),
                    GetTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    RefreshAccessToken = table.Column<string>(type: "TEXT", nullable: false),
                    ShopIdList = table.Column<string>(type: "TEXT", nullable: false),
                    MainAccountIdList = table.Column<string>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_UserInfo", x => x.ID);
                });

            migrationBuilder.CreateTable(
                name: "Value",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    ValueId = table.Column<long>(type: "INTEGER", nullable: false),
                    OriginalName = table.Column<string>(type: "TEXT", nullable: false),
                    DisplayName = table.Column<string>(type: "TEXT", nullable: false),
                    Unit = table.Column<string>(type: "TEXT", nullable: true),
                    Platform = table.Column<int>(type: "INTEGER", nullable: false),
                    AddTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    PTID = table.Column<string>(type: "TEXT", nullable: true),
                    DFID = table.Column<string>(type: "TEXT", nullable: true),
                    RSRID = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Value", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AreaCategoryRelation",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    AreaId = table.Column<int>(type: "INTEGER", nullable: false),
                    CId = table.Column<long>(type: "INTEGER", nullable: true),
                    CategoryStatus = table.Column<int>(type: "INTEGER", nullable: false),
                    OldCId = table.Column<long>(type: "INTEGER", nullable: true),
                    ExcuteTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    Platform = table.Column<int>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AreaCategoryRelation", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AreaCategoryRelation_Area_AreaId",
                        column: x => x.AreaId,
                        principalTable: "Area",
                        principalColumn: "AreaId",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AreaCategoryRelation_Category_CId",
                        column: x => x.CId,
                        principalTable: "Category",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "CategoryAttrRelation",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    CId = table.Column<long>(type: "INTEGER", nullable: false),
                    AttrId = table.Column<long>(type: "INTEGER", nullable: false),
                    AttributeStatus = table.Column<int>(type: "INTEGER", nullable: false),
                    OldAttrId = table.Column<long>(type: "INTEGER", nullable: true),
                    ExcuteTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    Platform = table.Column<int>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CategoryAttrRelation", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CategoryAttrRelation_Attribute_AttrId",
                        column: x => x.AttrId,
                        principalTable: "Attribute",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_CategoryAttrRelation_Category_CId",
                        column: x => x.CId,
                        principalTable: "Category",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AttrValueRelation",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    AttrId = table.Column<long>(type: "INTEGER", nullable: false),
                    VId = table.Column<long>(type: "INTEGER", nullable: false),
                    ValueStatus = table.Column<int>(type: "INTEGER", nullable: false),
                    OldVId = table.Column<long>(type: "INTEGER", nullable: true),
                    ExcuteTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    Platform = table.Column<int>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AttrValueRelation", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AttrValueRelation_Attribute_AttrId",
                        column: x => x.AttrId,
                        principalTable: "Attribute",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AttrValueRelation_Value_VId",
                        column: x => x.VId,
                        principalTable: "Value",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.InsertData(
                table: "Area",
                columns: new[] { "AreaId", "AreaName", "Platform", "ShopId", "ShorterForm" },
                values: new object[] { 1, "Singapore", 2, 32531, "SG" });

            migrationBuilder.InsertData(
                table: "Area",
                columns: new[] { "AreaId", "AreaName", "Platform", "ShopId", "ShorterForm" },
                values: new object[] { 2, "Malaysia", 2, 32541, "MY" });

            migrationBuilder.InsertData(
                table: "Area",
                columns: new[] { "AreaId", "AreaName", "Platform", "ShopId", "ShorterForm" },
                values: new object[] { 3, "Thailand", 2, 32539, "TH" });

            migrationBuilder.InsertData(
                table: "Area",
                columns: new[] { "AreaId", "AreaName", "Platform", "ShopId", "ShorterForm" },
                values: new object[] { 4, "Taiwan", 2, 33859, "TW" });

            migrationBuilder.InsertData(
                table: "Area",
                columns: new[] { "AreaId", "AreaName", "Platform", "ShopId", "ShorterForm" },
                values: new object[] { 5, "Indonesia", 2, 33863, "ID" });

            migrationBuilder.InsertData(
                table: "Area",
                columns: new[] { "AreaId", "AreaName", "Platform", "ShopId", "ShorterForm" },
                values: new object[] { 6, "Vietnam", 2, 32543, "VN" });

            migrationBuilder.InsertData(
                table: "Area",
                columns: new[] { "AreaId", "AreaName", "Platform", "ShopId", "ShorterForm" },
                values: new object[] { 7, "Philippines", 2, 32535, "PH" });

            migrationBuilder.InsertData(
                table: "Area",
                columns: new[] { "AreaId", "AreaName", "Platform", "ShopId", "ShorterForm" },
                values: new object[] { 8, "Brazil", 2, 33861, "BR" });

            migrationBuilder.CreateIndex(
                name: "IX_AreaCategoryRelation_AreaId",
                table: "AreaCategoryRelation",
                column: "AreaId");

            migrationBuilder.CreateIndex(
                name: "IX_AreaCategoryRelation_CId",
                table: "AreaCategoryRelation",
                column: "CId");

            migrationBuilder.CreateIndex(
                name: "IX_AttrValueRelation_AttrId",
                table: "AttrValueRelation",
                column: "AttrId");

            migrationBuilder.CreateIndex(
                name: "IX_AttrValueRelation_VId",
                table: "AttrValueRelation",
                column: "VId");

            migrationBuilder.CreateIndex(
                name: "IX_CategoryAttrRelation_AttrId",
                table: "CategoryAttrRelation",
                column: "AttrId");

            migrationBuilder.CreateIndex(
                name: "IX_CategoryAttrRelation_CId",
                table: "CategoryAttrRelation",
                column: "CId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AreaCategoryRelation");

            migrationBuilder.DropTable(
                name: "AttrValueRelation");

            migrationBuilder.DropTable(
                name: "CategoryAttrRelation");

            migrationBuilder.DropTable(
                name: "UserInfo");

            migrationBuilder.DropTable(
                name: "Area");

            migrationBuilder.DropTable(
                name: "Value");

            migrationBuilder.DropTable(
                name: "Attribute");

            migrationBuilder.DropTable(
                name: "Category");
        }
    }
}
